<?php
/**
 Template Name:women_list
 */
	
	$nowcatid = $_GET["nowcatid"];

	$siteurl = get_bloginfo('template_url');
	$pageSize = 10 ;
	$pageModel= 10 ; //不允许改变的值
	
	//网站355
	$selfPageLink = "?page_id=355&nowcatid=".$nowcatid; //自身链接；
	$autoLink = "" ;
	
	$paged = $_POST["paged"]; 
	if($paged == null || "" == $paged ){
		$paged = $_GET["paged"]; 
		if($paged == null || "" == $paged ){
			$paged = 0 ;
		}
	}
	$statNum = $pageSize * $paged ;
	//$numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'"); 

 	//if (0 < $numposts) $numposts = number_format($numposts);
 	$numposts =  wt_get_category_count($nowcatid);   
	global $wpdb;
get_header();
?>
	<script type="text/javascript">
	function DrawImage(ImgD,iwidth,iheight){       
		 var image=new Image();        
		 image.src=ImgD.src;        
		 if(image.width>0 && image.height>0){ 
			   if(image.width/image.height>= iwidth/iheight){
				   if(image.width>iwidth){ 
					    ImgD.width=iwidth;
					    ImgD.height=(image.height*iwidth)/image.width;
					}else{
					 ImgD.width=image.width;
					 ImgD.height=image.height;
					} 
					 }else{
						if(image.height>iheight){
						 ImgD.height=iheight;
						 ImgD.width=(image.width*iheight)/image.height;
					}else{
					ImgD.width=image.width;
					ImgD.height=image.height;
				}         

 }       
			    }   
		     }   
</script>

	<div id="cont">
		<div id="main">
			<div id="fudong">
				<div id="detail">
					<span id="mainbaoxie" class="lovelink2"><a href="www.uujog.com">index</a>=><?php
						 $categories = get_categories();
						  foreach ($categories as $cat) {
						  	$catid = $cat->cat_ID;
						  	if($catid == $nowcatid){
						  		echo $catname = $cat->name;
						  	}
						  } 
					 ?></span>
					<div id="c_left">
					 <?php
					 $nowcatid = $_GET["nowcatid"];
					//$contsql = "select * from $wpdb->posts  where post_status='publish' and post_type='post' ORDER BY post_date DESC LIMIT ".$statNum.",".$pageSize ;
					 //$myposts = $wpdb->get_results($contsql);
					//	foreach($myposts as $mypost){ 
					//		$postLink = get_permalink($mypost->ID);
					
					$postsql = "select post.guid as guid ,post.ID as ID,post.post_author as post_author,post.post_date as post_date,post.post_title as post_title,term.term_id as term_id ,post.post_content as post_content from wp_nwkvhq_terms term ,wp_nwkvhq_term_relationships ships, wp_nwkvhq_posts post where term.term_id = ships.term_taxonomy_id and post.ID = ships.object_id and term.term_id=$nowcatid  ORDER BY post.post_date DESC LIMIT $statNum,$pageSize"; 
					//$postsql = "select post.guid as guid ,post.ID as ID,post.post_author as post_author,post.post_date as post_date,post.post_title as post_title,term.term_id as term_id ,post.post_content as post_content from bw_terms term ,bw_term_relationships ships, bw_posts post where term.term_id = ships.term_taxonomy_id and post.ID = ships.object_id and term.term_id=$nowcatid  ORDER BY post.post_date DESC LIMIT $statNum,$pageSize"; 
					 
					$myposts = $wpdb->get_results($postsql);
					foreach($myposts as $mypost) {
	 
						$imgurl = get_first_image($mypost->post_content);
						 
					  ?>   
						<div class="c_leftlist" >
							<samp class="c_leftlistsamp"><a href="<?php echo $mypost->guid; ?>&nowcatid=<?php echo $nowcatid ?>"><img src="<?php echo $imgurl?>" onload="javascript:DrawImage(this,280,150)"  class="c_listimg" /></a></samp>
							<ul class="c_listul">
								<h5><a href="<?php echo $mypost->guid; ?>&nowcatid=<?php echo $nowcatid ?>"><?php echo $mypost->post_title; ?></a></h5>
								<li>Author：<?php 
								 $authorid = $mypost->post_author;
								 the_author_meta( "display_name", $authorid ); 							
								 ?></li>
								<li>Date：<?php echo $mypost->post_date ?></li>
							</ul>
							<p class="c_leftlistp"><?php echo mb_strimwidth(strip_tags(apply_filters('the_content', $mypost->post_content)), 0, 120,"…"); ?></p>
						</div>
						<?php }?>	
						
						<div id="scroll">
					<?php
					
					$totalPage = ceil($numposts/$pageSize) ;
					if($totalPage >0){
						$i = 0 ;
						$pagedLink = $selfPageLink;
						if(intval($paged) > 0 ){		
					?>
							<a href="<?php echo $pagedLink."&paged=".(intval($paged)-1); ?>" ><img src="<?php echo $siteurl ?>/images/next-top_en.gif" alt="Previous" title="Previous" class="f_l"/></a>
					<?php 
						}
					?>
					<?php 
						if($totalPage<=$pageModel){
						 	for(;$i<$totalPage;$i++){
						 		if($i == intval($paged)){
					?>
									<font class="linknone"><?php echo ($i +1);?></font>
					<?php 
						 		}else{
					?>
									<a href="<?php echo $pagedLink."&paged=".(intval($i)); ?>" class="linkstyle03"><?php echo ($i +1);?></a>
					<?php 
						 		}
						 	}
						 		
						}elseif($totalPage < $pageModel + 3){
							$halfPageModel = intval($pageModel /3)  ;
							if(intval($paged) < $halfPageModel*2){
								
								for($i=0;$i < $halfPageModel*2+1;$i++){
									if($i == intval($paged)){
					?>
										<font class="linknone"><?php echo ($i +1);?></font>
					<?php 
									}else{
					?>
										<a href="<?php echo $pagedLink."&paged=".(intval($i)); ?>" class="linkstyle03"><?php echo ($i +1);?></a>
					<?php 
									}
								}
					?>
								<a class="linkstyle03"><?php echo "...";?></a>
					<?php 		
								for($i = $totalPage-($pageModel-$halfPageModel*2 -2);$i<$totalPage;$i++){
					?>
									<a href="<?php echo $pagedLink."&paged=".(intval($i)); ?>" class="linkstyle03"><?php echo ($i +1);?></a>
					<?php 				
								}	
					?>
					<?php 
							}elseif(intval($paged) > $halfPageModel - 1) {
								for($i =0 ;$i< $halfPageModel-1;$i++){
					?>
									<a href="<?php echo $pagedLink."&paged=".(intval($i)); ?>" class="linkstyle03"><?php echo ($i +1);?></a>
					<?php 				
								}
					?>
								<a class="linkstyle03"><?php echo "...";?></a>
					<?php 	
								for($i=$totalPage-($pageModel-$halfPageModel);$i < $totalPage;$i++){
									if($i == intval($paged)){
					?>
										<font class="linknone"><?php echo ($i +1);?></font>
					<?php 
									}else{
					?>
										<a href="<?php echo $pagedLink."&paged=".(intval($i)); ?>" class="linkstyle03"><?php echo ($i +1);?></a>
					<?php 
									}
								}
							}
						}else{
							$halfPageModel = intval($pageModel /2)  ;
							if(intval($paged) < $halfPageModel-1){
								for($i =0 ;$i< $halfPageModel;$i++){
									if($i == intval($paged)){
					?>
										<font class="linknone"><?php echo ($i +1);?></font>
					<?php 
									}else{
					?>
										<a href="<?php echo $pagedLink."&paged=".(intval($i)); ?>" class="linkstyle03"><?php echo ($i +1);?></a>
					<?php 
									}
								}
					?>
								<a class="linkstyle03"><?php echo "...";?></a>
					<?php 			
								for($i =$totalPage - ($pageModel - $halfPageModel - 1) ;$i< $totalPage ;$i++){
					?>
									<a href="<?php echo $pagedLink."&paged=".(intval($i)); ?>" class="linkstyle03"><?php echo ($i +1);?></a>
					<?php				
								}
							}elseif(intval($paged) > $totalPage - ($halfPageModel) ) {
								for($i = 0 ;$i< $halfPageModel-1 ;$i++){
					?>
									<a href="<?php echo $pagedLink."&paged=".(intval($i)); ?>" class="linkstyle03"><?php echo ($i +1);?></a>
					<?php				
								}
					?>
								<a class="linkstyle03"><?php echo "...";?></a>
					<?php 		
								for($i = $totalPage - ($pageModel - $halfPageModel) ;$i< $totalPage;$i++){
									if($i == intval($paged)){
					?>
										<font class="linknone"><?php echo ($i +1);?></font>
					<?php 
									}else{
					?>
										<a href="<?php echo $pagedLink."&paged=".(intval($i)); ?>" class="linkstyle03"><?php echo ($i +1);?></a>
					<?php 
									}
								}	
								
							}else {
					?>
								<a href="<?php echo $pagedLink."&paged=0"; ?>" class="linkstyle03"><?php echo 1;?></a>
								<a href="<?php echo $pagedLink."&paged=1"; ?>" class="linkstyle03"><?php echo 2;?></a>
					<?php 
								$uses = 3 ;
								if($paged > $totalPage/2){
									$uses = 2 ;
					?>
									<a href="<?php echo $pagedLink."&paged=1"; ?>" class="linkstyle03"><?php echo 3;?></a>
					<?php				
								}
					?>
								<a class="linkstyle03"><?php echo "...";?></a>
								<a href="<?php echo $pagedLink."&paged=".(intval($paged)-1); ?>" class="linkstyle03"><?php echo intval($paged);?></a>
								<font class="linknone"><?php echo (intval($paged) +1);?></font>
								<a href="<?php echo $pagedLink."&paged=".(intval($paged)+1); ?>" class="linkstyle03"><?php echo (intval($paged) +2);?></a>
								<a class="linkstyle03"><?php echo "...";?></a>
					<?php 		
								for($i = $totalPage - $uses ;$i< $totalPage;$i++){
					?>
										<a href="<?php echo $pagedLink."&paged=".(intval($i)); ?>" class="linkstyle03"><?php echo ($i +1);?></a>
					<?php 
								}
							}
						}						
						if(intval($paged)<$totalPage-1){
					?>
							<a href="<?php echo $pagedLink."&paged=".(intval($paged)+1); ?>" ><img src="<?php echo $siteurl ?>/images/next-bottom_en.gif" alt="next" title="next" class="f_l" /></a>
					<?php 
						}
					}
					?>
				</div>
					</div>
					<div id="detail_right">
						<h2 id="zuilove">Top</h2>
						<ul id="detail_right_left">
						<?php
							query_posts('showposts=12&orderby=date&cat='.$nowcatid);
								
							$i=0;
							
							if ( have_posts() ) : while ( have_posts() ) : the_post();
							$i++;
							if($i <=3){
						?>
							<li class="lovelink1"><?php echo $i; ?>&nbsp;<a href="<?php echo the_permalink(); ?>&nowcatid=<?php echo $nowcatid ?>"><?php the_title(); ?></a></li>
						<?php 
							}else{
						?>
							<li class="lovelink2"><?php echo $i; ?>&nbsp;<a href="<?php echo the_permalink(); ?>&nowcatid=<?php echo $nowcatid ?>"><?php the_title(); ?></a></li>
						<?php }
							endwhile; else:
							endif;
							wp_reset_query();
						?>
						</ul>
					</div>
				</div>
			</div>
			<div id="moduan"></div>
		</div>
	</div>
<?php get_footer();?>